@echo off
echo ========================================
echo 医疗管理系统功能测试脚本
echo ========================================
echo.

REM 设置变量
set BASE_URL=http://localhost:8080
set TOKEN=

echo 1. 测试系统连接...
curl -s -o nul -w "HTTP状态码: %%{http_code}\n" %BASE_URL%/swagger-ui.html
if %errorlevel% neq 0 (
    echo 错误: 无法连接到系统，请确保应用已启动
    pause
    exit /b 1
)
echo 系统连接正常！
echo.

echo 2. 测试登录功能...
echo 正在登录管理员账户...
for /f "tokens=*" %%i in ('curl -s -X POST %BASE_URL%/api/login -H "Content-Type: application/x-www-form-urlencoded" -d "username=admin&password=123456"') do set LOGIN_RESPONSE=%%i
echo 登录响应: %LOGIN_RESPONSE%
echo.

echo 3. 提取Token...
for /f "tokens=2 delims=:" %%a in ('echo %LOGIN_RESPONSE% ^| findstr "token"') do (
    set TOKEN_RAW=%%a
)
for /f "tokens=1 delims=," %%b in ("%TOKEN_RAW%") do (
    set TOKEN=%%b
)
set TOKEN=%TOKEN:"=%
set TOKEN=%TOKEN: =%
echo 提取到的Token: %TOKEN%
echo.

if "%TOKEN%"=="" (
    echo 错误: 无法获取Token，请检查登录响应
    pause
    exit /b 1
)

echo 4. 测试获取仪表板数据...
curl -s -X GET %BASE_URL%/api/dashboard -H "Authorization: %TOKEN%"
echo.
echo.

echo 5. 测试获取医生列表...
curl -s -X GET %BASE_URL%/api/doctors -H "Authorization: %TOKEN%"
echo.
echo.

echo 6. 测试获取药品列表...
curl -s -X GET %BASE_URL%/api/drugs/1/10 -H "Authorization: %TOKEN%"
echo.
echo.

echo 7. 测试获取材料列表...
curl -s -X GET %BASE_URL%/api/materials/1/10 -H "Authorization: %TOKEN%"
echo.
echo.

echo 8. 测试获取药店列表...
curl -s -X GET %BASE_URL%/api/sales/1/10 -H "Authorization: %TOKEN%"
echo.
echo.

echo 9. 测试获取城市列表...
curl -s -X GET %BASE_URL%/api/cities -H "Authorization: %TOKEN%"
echo.
echo.

echo 10. 测试获取公司列表...
curl -s -X GET %BASE_URL%/api/companys/1/10 -H "Authorization: %TOKEN%"
echo.
echo.

echo ========================================
echo 测试完成！
echo ========================================
echo.
echo 如果看到JSON响应数据，说明系统运行正常
echo 如果看到错误信息，请检查：
echo 1. 应用是否已启动
echo 2. 数据库是否已初始化
echo 3. 网络连接是否正常
echo.
pause




